/**
 *       Copyright (c) 2012 Lukas Zaruba
 *
 *   This file is part of Robot Playground.
 *
 *   Robot Playground is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Robot Playground is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public License
 *   along with Robot Playground. If not, see <http://www.gnu.org/licenses/>.
 */
package net.zarubsys.robotplayground.gui.application;

import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.actions.ContributionItemFactory;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

/**
 * ApplicationActionBarAdvisor
 *
 * @author Lukas Zaruba, lukas.zaruba@gmail.com
 */
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
	
	private IWorkbenchAction newWizardDrop;
	private IWorkbenchAction exitAction;
	private IWorkbenchAction aboutAction;
	private IWorkbenchAction preferencesAction;
	private IWorkbenchAction saveAction;
	private IWorkbenchAction saveAsAction;
	private IWorkbenchAction newWizard;
	private IWorkbenchAction saveAllAction;
	private IWorkbenchAction helpAction;
	private IWorkbenchAction helpSearchAction;
	private IContributionItem openPerspective;
	private IContributionItem showView;
	private IWorkbenchAction resetPerspective;
	private MenuManager showViewMenuManager;
	private MenuManager openPerspectiveMenuManager;

    public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
        super(configurer);
    }

    @Override
	protected void makeActions(IWorkbenchWindow window) {
    	newWizard = ActionFactory.NEW.create(window);
    	register(newWizard);
    	
    	newWizardDrop = ActionFactory.NEW_WIZARD_DROP_DOWN.create(window);
    	register(newWizardDrop);
    	
    	exitAction = ActionFactory.QUIT.create(window);
    	register(exitAction);
    	
    	aboutAction = ActionFactory.ABOUT.create(window);
    	register(aboutAction);
    	
    	preferencesAction = ActionFactory.PREFERENCES.create(window);
    	register(preferencesAction);
    	
    	saveAction = ActionFactory.SAVE.create(window);
    	register(saveAction);
    	
    	saveAsAction = ActionFactory.SAVE_AS.create(window);
    	register(saveAsAction);
    	
    	saveAllAction = ActionFactory.SAVE_ALL.create(window);
    	register(saveAllAction);
    	
    	helpAction = ActionFactory.HELP_CONTENTS.create(window);
    	register(helpAction);
    	
    	helpSearchAction = ActionFactory.HELP_SEARCH.create(window);
    	register(helpSearchAction);
    	
    	showViewMenuManager = new MenuManager("Show View", "showView");
    	showView = ContributionItemFactory.VIEWS_SHORTLIST.create(window);
    	
    	openPerspectiveMenuManager = new MenuManager("Open Perspective", "openPerspective");
    	openPerspective = ContributionItemFactory.PERSPECTIVES_SHORTLIST.create(window);
    	
    	resetPerspective = ActionFactory.RESET_PERSPECTIVE.create(window);
    	register(resetPerspective);
    }

    @Override
	protected void fillMenuBar(IMenuManager menuBar) {
    	IMenuManager mainMenu = new MenuManager("Main", "robotPlayground"); //$NON-NLS-1$ //$NON-NLS-2$
    	mainMenu.add(newWizard);
    	mainMenu.add(saveAction);
    	mainMenu.add(saveAsAction);
    	mainMenu.add(saveAllAction);
    	mainMenu.add(new Separator());
    	mainMenu.add(exitAction);
    	
    	MenuManager windowMenu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW);
    	openPerspectiveMenuManager.add(openPerspective);
    	windowMenu.add(openPerspectiveMenuManager);
    	
    	showViewMenuManager.add(showView);
    	windowMenu.add(showViewMenuManager);
    	
    	windowMenu.add(resetPerspective);
    	windowMenu.add(new Separator());
    	windowMenu.add(preferencesAction);
    	
    	IMenuManager helpMenu = new MenuManager("&Help", "help"); //$NON-NLS-1$ //$NON-NLS-2$
    	helpMenu.add(new Separator());
    	helpMenu.add(helpAction);
    	helpMenu.add(helpSearchAction);
    	helpMenu.add(new Separator());
    	helpMenu.add(aboutAction);
    	
    	menuBar.add(mainMenu);
    	menuBar.add(windowMenu);
    	menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    	menuBar.add(helpMenu);
    }
    
    @Override
    protected void fillCoolBar(ICoolBarManager coolBar) {
    	IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle() | SWT.BOTTOM);
    	coolBar.add(toolbar);
    	ActionContributionItem newWizardCI = new ActionContributionItem(newWizardDrop);
    	toolbar.add(newWizardCI);
    	ActionContributionItem saveCI = new ActionContributionItem(saveAction);
    	toolbar.add(saveCI);
    	ActionContributionItem saveAsCI = new ActionContributionItem(saveAsAction);
    	toolbar.add(saveAsCI);
    }

}

